<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CreateOrderTransportsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 收货时间: 当用户主动确认收货，或者订单超时系统自动确认收货时，更新收货时间
        if (!Schema::hasTable('order_transports')) {
            Schema::create('order_transports', function (Blueprint $table) {
                $table->id();
                $table->integer('order_id')->comment('订单id');
                $table->string('order_num')->comment('订单号');
                // $table->integer('order_product_id')->comment('订单产品id');
                $table->string('province')->comment('收货省份');
                $table->string('city')->comment('收货城市');
                $table->string('area')->comment('收货区域');
                $table->string('address')->comment('收货地址');
                $table->string('contacts')->comment('收货联系人');
                $table->string('phone')->comment('收货联系电话');
                $table->integer('cost_price')->default(0)->comment('运费');
                $table->tinyInteger('transport_type')->default(0)->comment('运输类型:0快递,1自提');
                $table->string('express_name')->nullable()->comment('快递公司');
                $table->string('express_code')->nullable()->comment('快递公司编号');
                $table->string('express_num')->nullable()->comment('快递单号');
                $table->timestamp('delivery_time')->nullable()->comment('发货时间');// 后台运营人员自主录入
                $table->timestamp('receive_time')->nullable()->comment('收货时间');
                $table->string('remark')->nullable()->comment('备注');
                $table->tinyInteger('status')->default(0)->comment('状态:0待发货,1已发货,2已收货');
                // 快递信息对接方：快递100(有回调) 或 阿里云市场
                // $table->string('express_user')->nullable()->comment('快递员');
                // $table->string('express_user_mobile')->nullable()->comment('快递员电话');
                // $table->tinyInteger('express_status')->comment('快递状态:已签收,派送中,运输中,已发货,(已打包,)已下单');
                $table->index(['order_id', 'order_num']);
                $table->softDeletes();
                $table->timestamps();
            });
            DB::statement("ALTER TABLE `order_transports` comment '订单运单表'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_transports');
    }
}
